<template>
	<view class="flex justify-end">
		<my-switch :checked="!isEmpty(data?.onValue) ? modelValue == data.onValue : modelValue" @change="change"></my-switch>
	</view>
</template>

<script setup lang="ts">
// import { ref, watch } from 'vue'
import { isEmpty } from '@/assets/js/utils'

const props = defineProps({
	//表单组件参数
	data: {
		type: Object,
	},
	modelValue: {}
})

//修改双向绑定值
const emit = defineEmits(['update:modelValue','change'])
const change = (e: any) => {
	let value: any
	if (!isEmpty(props.data?.onValue) && e.detail.value) {
		value = props.data.onValue
	} else if (!isEmpty(props.data?.offValue) && !e.detail.value) {
		value = props.data.offValue
	} else {
		value = e.detail.value
	}
	emit('update:modelValue', value)
	emit('change', value)
}
</script>
